package com.shop.web.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.dao.ProductDao;
import com.shop.domain.Order;
import com.shop.domain.PageBean;
import com.shop.domain.Product;
import com.shop.service.ProductService;

/**
 * 分页查询
 * @author Administrator
 *
 */
public class PageQueryServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pnum = request.getParameter("pnum");
		String regex = "\\d+";  //[0-9]+
		if (!pnum.matches(regex)) {
			return;
		}else {
			int num = Integer.parseInt(pnum);
			//List<Product> products = new ProductService().findAll(num);
			PageBean pageBean = new ProductService().findByPage(num);
			request.setAttribute("pageBean", pageBean);
			request.getRequestDispatcher("/list_page.jsp").forward(request, response);
		}
		
	}

}
